﻿<html>
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width,initial-scale=1"/>
    <title>个人中心 - 橘子财税，办税不累</title>
    <link rel="shortcut icon" href="static/images/logo.jpg" type="image/x-icon"/>
    <link href="./static/css/app.aa50d7a1e10eaca07f2a864238d3577a.css" rel="stylesheet"/>
    <script type="text/javascript" src="static/js/vue.js"></script>
    <script type="text/javascript" src="static/js/axios.min.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <style>
        .hover-list{
            display: block;
            color: #666;
        }
        .hover-list:hover{
            cursor: pointer;
            color: #72b1ff;
        }
        .el-table{
            color: #999;
        }
    </style>
</head>
<body>
<div id="app">
    <div id="header">
        <div class="header">
            <a href="http://www.caishuib.com">
                <img src="static/images/logo.jpg" alt="橘子财税" class="logo">
            </a>
            <ul class="menu">
                <li class=""><a href="people.html" style="color: #fff;display: block;height: 100%;width: 100%;">首页</a> <img
                        src=""
                        class="triangle-tips"/></li>
                <li class=""> <a href="changePass.html" style="color: #fff;display: block;height: 100%;width: 100%;">账户设置</a>  <img
                        src=""
                        class="triangle-tips"/></li>
            </ul>
            <a href="http://xiaopengbest.cn/index.html" class="toindex">叮叮财税首页</a>
            <a class="outlogin" @click="loginOut">退出登录</a>
        </div>
    </div>
    <div id="body">
        <div>
            <div class="Sidebar">
                <div class="content">
                    <p class="title">账号管理</p>
                    <div>
                        <a href="people.html" class="">个人资料</a>
                    </div>
                    <div>
                        <a href="changePass.html" class="router-link-exact-active router-link-active">密码修改</a>
                    </div>
                </div>
                <div class="content">
                    <p class="title">收藏记录</p>
                    <div>
                        <a href="shouCang.html" class="">我的收藏</a>
                    </div>
                </div>
                <div class="content">
                    <p class="title">历史记录</p>
                    <div>
                        <a href="home.html" >咨询记录</a>
                    </div>
                    <div>
                        <a href="keChengJiLu.html" >课程记录</a>
                    </div>
                </div>
            </div>
            <div id="main">
                <div id="title">
                    <span class="title">密码修改</span>
                </div>
                <div id="content">
                    <div class="comment1">
                        <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                            <el-form-item label="旧密码" prop="old_pass">
                                <el-input type="text" v-model="ruleForm.old_pass" autocomplete="off" style="width: 500px;"></el-input>
                            </el-form-item>
                            <el-form-item label="新密码" prop="new_pass">
                                <el-input type="password" v-model="ruleForm.new_pass" autocomplete="off" style="width: 500px;"></el-input>
                            </el-form-item>
                            <el-form-item label="确认密码" prop="check_pass">
                                <el-input type="password" v-model="ruleForm.check_pass" autocomplete="off" style="width: 500px;"></el-input>
                            </el-form-item>
                            <el-form-item style="text-align: center">
                                <el-button type="primary" :loading="loading" @click="submitForm('ruleForm')">{{loading?'修改中':'点击修改'}}</el-button>
                            </el-form-item>
                        </el-form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="https://hm.baidu.com/hm.js?a71c3d484b2419b0d94468789f7f49e1"></script>
<script type="text/javascript">var _hmt = _hmt || [];
(function () {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?a71c3d484b2419b0d94468789f7f49e1";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>

</body>
<script type="text/javascript">
    var validatePass = (rule, value, callback) => {
        if (value === '') {
            callback(new Error('请输入密码'));
        } else {
            if (app.ruleForm.check_pass !== '') {
                app.$refs.ruleForm.validateField('check_pass');
            }
            callback();
        }
    };
    var validatePass2 = (rule, value, callback) => {
        if (value === '') {
            callback(new Error('请再次输入密码'));
        } else if (value !== app.ruleForm.new_pass) {
            callback(new Error('两次输入密码不一致!'));
        } else {
            callback();
        }
    };
 var app =  new Vue({
        el: '#app',
        data: {
            ruleForm: {
                old_pass: '',
                check_pass: '',
                new_pass: ''
            },
            rules: {
                new_pass: [
                    { validator: validatePass, trigger: 'change' }
                ],
                check_pass: [
                    { validator: validatePass2, trigger: 'change' }
                ],
                old_pass:[
                    { required: true, message: '请输入旧密码', trigger: 'change' }
                ]
            },
            pageInfo: {
                per_page: 6,
                total: 0,
                current_page: 1
            },
            contentData: [],
            token: '',
            userPhone: '',
            userInfo: {},
            loading:false,
            keHttp: 'http://xiaopengbest.cn/api/user/session/password',
        },
        watch: {
            loginDialogVisible: function (val) {
                if (!val) {
                    Object.keys(this.form).forEach(key => this.form[key] = '');
                    this.$refs['form'].resetFields();
                }
            },
            isLogin: function (val) {
                if (val) {
                    this.title = '登录';
                } else {
                    this.title = '注册';
                }
            }
        },
        created() {
            this.token = localStorage.getItem('token');
            if(this.token){
                this.token =(this.token.replace('"',''));
            }
            this.userPhone = localStorage.getItem('userInfo') ? JSON.parse(localStorage.getItem('userInfo')).phone : '';
            this.userInfo = localStorage.getItem('userInfo') ? JSON.parse(localStorage.getItem('userInfo')) : '';
            // this.keHttp = this.keHttp + this.userInfo.id
        },
        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        this.changePass();
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            loginOut() {
                localStorage.clear();
                // window.location.href = 'http://localhost:63342/vueding/index.html';
                window.location.href = 'http://xiaopengbest.cn/index.html';
            },
            changePass() {
                this.loading = true;
                axios.put(this.keHttp, {
                    oldpwd:this.ruleForm.old_pass,
                    newpwd:this.ruleForm.new_pass
                },{
                    headers: {
                        "Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
                        'Authorization': 'Bearer ' + this.token
                    },
                    transformRequest: [function (data) {
                        let ret = '';
                        for (let it in data) {
                            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                        }
                        return ret
                    }]
                }).then((res) => {
                    if (res.data.code == 200) {
                        this.$message({
                            message:'密码修改成功',
                            duration: 1000,
                            type:'success'
                        });
                        Object.keys(this.ruleForm).forEach(key => this.ruleForm[key] = '');
                        this.$refs['ruleForm'].resetFields();
                    }
                    this.loading = false;
                }).catch((err) => {
                    this.loading = false;
                    this.$message.warning(err.response.data.msg || "数据异常，请重试");
                });
            }
        }
    });
</script>
</html>
